#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <errno.h>
#include <time.h>
/* 这是一个创建了n个进程组成的进程链的程序，其中n是命令行参数*/

int main(int argc, char *argv[]){
	pid_t child_pid;

	child_pid = fork();		// 在这里创建信号处理函数

	if(child_pid == -1){
		perror("Failed to fork()");
		return -1;
	}

	if(child_pid == 0){
		fprintf(stderr, "I am child %ld\n", (long)getpid());
	}else if(wait(NULL) != child_pid){
		fprintf(stderr, "A signal must have interrupted the wait!\n");
	}else{
		fprintf(stderr, "I am parent %ld with child %ld\n", (long)getpid(), (long)child_pid);
	}
	
	return 0;
}

